using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region Attachment

	/// <summary>
	/// Attachment object for NHibernate mapped table 'Attachment'.
	/// </summary>
	[Serializable]
	public class Attachment : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _fileName;
		protected string _filePath;
		protected string _owner;
		protected Nullables.NullableDateTime _date;
		protected Application _application;
		protected ActionPoint _actionPoint;
		protected DicItem _attachmentType;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public Attachment() { }

		public Attachment( string fileName, string filePath, string owner, Nullables.NullableDateTime date, Application application, ActionPoint actionPoint, DicItem attachmentType )
		{
			this._fileName = fileName;
			this._filePath = filePath;
			this._owner = owner;
			this._date = date;
			this._application = application;
			this._actionPoint = actionPoint;
			this._attachmentType = attachmentType;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string FileName
		{
			get { return _fileName; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for FileName", value, value.ToString());
				_fileName = value;
			}
		}

		public string FilePath
		{
			get { return _filePath; }
			set
			{
				if ( value != null && value.Length > 1000)
					throw new ArgumentOutOfRangeException("Invalid value for FilePath", value, value.ToString());
				_filePath = value;
			}
		}

		public string Owner
		{
			get { return _owner; }
			set
			{
				if ( value != null && value.Length > 250)
					throw new ArgumentOutOfRangeException("Invalid value for Owner", value, value.ToString());
				_owner = value;
			}
		}

		public Nullables.NullableDateTime Date
		{
			get { return _date; }
			set { _date = value; }
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public ActionPoint ActionPoint
		{
			get { return _actionPoint; }
			set { _actionPoint = value; }
		}

		public DicItem AttachmentType
		{
			get { return _attachmentType; }
			set { _attachmentType = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is Attachment))
				throw new InvalidCastException("This object is not of type Attachment");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((Attachment)obj).Id);
					break;
				case "FileName":
						relativeValue = ( this.FileName != null ) ? this.FileName.CompareTo(((Attachment)obj).FileName) : -1;
					break;
				case "FilePath":
						relativeValue = ( this.FilePath != null ) ? this.FilePath.CompareTo(((Attachment)obj).FilePath) : -1;
					break;
				case "Owner":
						relativeValue = ( this.Owner != null ) ? this.Owner.CompareTo(((Attachment)obj).Owner) : -1;
					break;
				case "Date":
						relativeValue = ( this.Date != null ) ? this.Date.CompareTo(((Attachment)obj).Date) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (Attachment.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
